package com.zmovie.front.interceptor;

import com.zmovie.framework.domain.User;
import com.zmovie.front.constant.Constants;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author 挚爱之夕
 * @version 1.0
 * @implSpec 用户权限校验拦截器
 * @since 2023-12-12 11:06
 */
public class UserLoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request,
                             HttpServletResponse response,
                             Object handler) throws Exception {
        User user = (User) request.getSession().getAttribute(Constants.SESSION_USER_KEY);
        if (user == null) {
            response.sendRedirect("/login");
            return false;
        }
        return true;
    }
}
